package com.jwsoft.manager.core.gateway.controller;

import com.alibaba.fastjson.JSON;
import com.bifang.assistant.common.vo.BaseVO;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.protect.core.annotation.NoSignCrypto;
import com.bifang.module.base.common.vo.dict.SelectVO;
import com.bifang.module.base.common.vo.excel.ExcelVO;
import com.bifang.module.base.core.utils.ServiceRequestUtil;
import com.jwsoft.manager.common.vo.common.recruitStudent.RecruitStudentSyncRetVO;
import com.jwsoft.manager.common.vo.common.recruitStudent.SyncStudentQueryVO;
import com.jwsoft.manager.common.vo.eduSyncDyApply.EduSyncDyApplyQueryVO;
import com.jwsoft.manager.common.vo.eduSyncZjApply.EduSyncZjApplyKeyVO;
import com.jwsoft.manager.common.vo.eduSyncZjApply.EduSyncZjApplyQueryVO;
import com.jwsoft.manager.common.vo.eduSyncZjApply.EduSyncZjApplyVO;
import com.jwsoft.manager.common.vo.eduSyncZjApprove.EduSyncZjApproveKeyVO;
import com.jwsoft.manager.common.vo.eduSyncZjApprove.EduSyncZjApproveQueryVO;
import com.jwsoft.manager.common.vo.eduSyncZjApprove.EduSyncZjApproveVO;
import com.jwsoft.manager.common.vo.eduSyncZjDelete.EduSyncZjDeleteKeyVO;
import com.jwsoft.manager.common.vo.eduSyncZjDelete.EduSyncZjDeleteQueryVO;
import com.jwsoft.manager.common.vo.eduSyncZjDelete.EduSyncZjDeleteVO;
import com.jwsoft.manager.core.integration.EduSyncZjApplyIntegration;
import com.jwsoft.manager.core.integration.EduSyncZjApproveIntegration;
import com.jwsoft.manager.core.integration.EduSyncZjDeleteIntegration;
import com.jwsoft.manager.core.integration.EduSyncZjEnrollIntegration;
import com.jwsoft.manager.common.vo.eduSyncZjEnroll.EduSyncZjEnrollVO;
import com.jwsoft.manager.common.vo.eduSyncZjEnroll.EduSyncZjEnrollKeyVO;
import com.jwsoft.manager.common.vo.eduSyncZjEnroll.EduSyncZjEnrollQueryVO;
import com.github.pagehelper.PageInfo;
import com.bifang.engine.assistant.core.domain.AppResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import com.bifang.engine.protect.core.annotation.Idempotent;
import org.springframework.validation.annotation.Validated;
import com.bifang.assistant.common.constants.Validators;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 省招生报名专库同步管理网关
 *
 * @author chenzh
 * @since 2023-07-25
 */
@RestController
@RequestMapping(value = "/doc/api")
@Tag(name = "省招生报名专库同步管理", description = "省招生报名专库同步管理")
public class EduSyncZjController {
    @Autowired
    public EduSyncZjApplyIntegration eduSyncZjApplyIntegration;
    @Autowired
    public EduSyncZjEnrollIntegration eduSyncZjEnrollIntegration;
    @Autowired
    public EduSyncZjApproveIntegration eduSyncZjApproveIntegration;
    @Autowired
    public EduSyncZjDeleteIntegration eduSyncZjDeleteIntegration;

    @Operation(summary = "省招生报名专库同步管理-报名数据分页查询", description = "省招生报名专库同步管理-报名数据分页查询")
    @PostMapping(value = "/eduSyncZj0001", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduSyncZjApplyVO>> getList(@RequestBody @Validated EduSyncZjApplyQueryVO vo) {
        return AppResponse.successData(eduSyncZjApplyIntegration.getList(vo));
    }

    @Operation(summary = "省招生报名专库同步管理-报名数据根据主键查询详情", description = "省招生报名专库同步管理-报名数据根据主键查询详情")
    @PostMapping(value = "/eduSyncZj0002", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSyncZjApplyVO> getById(@RequestBody @Validated EduSyncZjApplyKeyVO vo) {
        return AppResponse.successData(eduSyncZjApplyIntegration.getById(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-报名数据新增", description = "省招生报名专库同步管理-报名数据新增")
    @PostMapping(value = "/eduSyncZj0004", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSyncZjApplyVO> add(@RequestBody @Validated(value = {Validators.Add.class}) EduSyncZjApplyVO vo) {
        return AppResponse.successData(eduSyncZjApplyIntegration.add(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-报名数据修改", description = "省招生报名专库同步管理-报名数据修改")
    @PostMapping(value = "/eduSyncZj0005", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSyncZjApplyVO> edit(@RequestBody @Validated(value = {Validators.Edit.class}) EduSyncZjApplyVO vo) {
        return AppResponse.successData(eduSyncZjApplyIntegration.edit(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-报名数据删除", description = "省招生报名专库同步管理-报名数据删除")
    @PostMapping(value = "/eduSyncZj0006", produces = "application/json;charset=UTF-8")
    public AppResponse del(@RequestBody @Validated EduSyncZjApplyKeyVO vo) {
        eduSyncZjApplyIntegration.del(vo);
        return AppResponse.successMsg("删除成功！");
    }

    @Operation(summary = "省招生报名专库同步管理-报名审核数据分页查询", description = "省招生报名专库同步管理-报名审核数据分页查询")
    @PostMapping(value = "/eduSyncZj0007", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduSyncZjApproveVO>> getList(@RequestBody @Validated EduSyncZjApproveQueryVO vo) {
        return AppResponse.successData(eduSyncZjApproveIntegration.getList(vo));
    }

    @Operation(summary = "省招生报名专库同步管理-报名审核数据根据主键查询详情", description = "省招生报名专库同步管理-报名审核数据根据主键查询详情")
    @PostMapping(value = "/eduSyncZj0008", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSyncZjApproveVO> getById(@RequestBody @Validated EduSyncZjApproveKeyVO vo) {
        return AppResponse.successData(eduSyncZjApproveIntegration.getById(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-报名审核数据新增", description = "省招生报名专库同步管理-报名审核数据新增")
    @PostMapping(value = "/eduSyncZj0009", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSyncZjApproveVO> add(@RequestBody @Validated(value = {Validators.Add.class}) EduSyncZjApproveVO vo) {
        return AppResponse.successData(eduSyncZjApproveIntegration.add(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-报名审核数据修改", description = "省招生报名专库同步管理-报名审核数据修改")
    @PostMapping(value = "/eduSyncZj0010", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSyncZjApproveVO> edit(@RequestBody @Validated(value = {Validators.Edit.class}) EduSyncZjApproveVO vo) {
        return AppResponse.successData(eduSyncZjApproveIntegration.edit(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-报名审核数据删除", description = "省招生报名专库同步管理-报名审核数据删除")
    @PostMapping(value = "/eduSyncZj0011", produces = "application/json;charset=UTF-8")
    public AppResponse del(@RequestBody @Validated EduSyncZjApproveKeyVO vo) {
        eduSyncZjApproveIntegration.del(vo);
        return AppResponse.successMsg("删除成功！");
    }

    @Operation(summary = "省招生报名专库同步管理-报名录取数据分页查询", description = "省招生报名专库同步管理-报名录取数据分页查询")
    @PostMapping(value = "/eduSyncZj0012", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduSyncZjEnrollVO>> getList(@RequestBody @Validated EduSyncZjEnrollQueryVO vo) {
        return AppResponse.successData(eduSyncZjEnrollIntegration.getList(vo));
    }

    @Operation(summary = "省招生报名专库同步管理-报名录取数据根据主键查询详情", description = "省招生报名专库同步管理-报名录取数据根据主键查询详情")
    @PostMapping(value = "/eduSyncZj0013", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSyncZjEnrollVO> getById(@RequestBody @Validated EduSyncZjEnrollKeyVO vo) {
        return AppResponse.successData(eduSyncZjEnrollIntegration.getById(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-报名录取数据新增", description = "省招生报名专库同步管理-报名录取数据新增")
    @PostMapping(value = "/eduSyncZj0014", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSyncZjEnrollVO> add(@RequestBody @Validated(value = {Validators.Add.class}) EduSyncZjEnrollVO vo) {
        return AppResponse.successData(eduSyncZjEnrollIntegration.add(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-报名录取数据修改", description = "省招生报名专库同步管理-报名录取数据修改")
    @PostMapping(value = "/eduSyncZj0015", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSyncZjEnrollVO> edit(@RequestBody @Validated(value = {Validators.Edit.class}) EduSyncZjEnrollVO vo) {
        return AppResponse.successData(eduSyncZjEnrollIntegration.edit(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-报名录取数据删除", description = "省招生报名专库同步管理-报名录取数据删除")
    @PostMapping(value = "/eduSyncZj0016", produces = "application/json;charset=UTF-8")
    public AppResponse del(@RequestBody @Validated EduSyncZjEnrollKeyVO vo) {
        eduSyncZjEnrollIntegration.del(vo);
        return AppResponse.successMsg("删除成功！");
    }

    @Operation(summary = "省招生报名专库同步管理-删除信息分页查询", description = "省招生报名专库同步管理-删除信息分页查询")
    @PostMapping(value = "/eduSyncZj0017", produces = "application/json;charset=UTF-8")
    public AppResponse<PageInfo<EduSyncZjDeleteVO>> getList(@RequestBody @Validated EduSyncZjDeleteQueryVO vo) {
        return AppResponse.successData(eduSyncZjDeleteIntegration.getList(vo));
    }

    @Operation(summary = "省招生报名专库同步管理-删除信息根据主键查询详情", description = "省招生报名专库同步管理-删除信息根据主键查询详情")
    @PostMapping(value = "/eduSyncZj0018", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSyncZjDeleteVO> getById(@RequestBody @Validated EduSyncZjDeleteKeyVO vo) {
        return AppResponse.successData(eduSyncZjDeleteIntegration.getById(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-删除信息新增", description = "省招生报名专库同步管理-删除信息新增")
    @PostMapping(value = "/eduSyncZj0019", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSyncZjDeleteVO> add(@RequestBody @Validated(value = {Validators.Add.class}) EduSyncZjDeleteVO vo) {
        return AppResponse.successData(eduSyncZjDeleteIntegration.add(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-删除信息修改", description = "省招生报名专库同步管理-删除信息修改")
    @PostMapping(value = "/eduSyncZj0020", produces = "application/json;charset=UTF-8")
    public AppResponse<EduSyncZjDeleteVO> edit(@RequestBody @Validated(value = {Validators.Edit.class}) EduSyncZjDeleteVO vo) {
        return AppResponse.successData(eduSyncZjDeleteIntegration.edit(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-删除信息删除", description = "省招生报名专库同步管理-删除信息删除")
    @PostMapping(value = "/eduSyncZj0021", produces = "application/json;charset=UTF-8")
    public AppResponse del(@RequestBody @Validated EduSyncZjDeleteKeyVO vo) {
        eduSyncZjDeleteIntegration.del(vo);
        return AppResponse.successMsg("删除成功！");
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-报名信息同步", description = "省招生报名专库同步管理-报名信息同步")
    @PostMapping(value = "/eduSyncZj0022", produces = "application/json;charset=UTF-8")
    public AppResponse<RecruitStudentSyncRetVO> syncBm(@RequestBody @Validated EduSyncZjApplyKeyVO vo) {
        return AppResponse.successData(eduSyncZjApplyIntegration.sync(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-报名审核信息同步", description = "省招生报名专库同步管理-报名审核信息同步")
    @PostMapping(value = "/eduSyncZj0023", produces = "application/json;charset=UTF-8")
    public AppResponse<RecruitStudentSyncRetVO> syncSh(@RequestBody @Validated EduSyncZjApproveKeyVO vo) {
        return AppResponse.successData(eduSyncZjApproveIntegration.sync(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-报名录取信息同步", description = "省招生报名专库同步管理-报名录取信息同步")
    @PostMapping(value = "/eduSyncZj0024", produces = "application/json;charset=UTF-8")
    public AppResponse<RecruitStudentSyncRetVO> syncLq(@RequestBody @Validated EduSyncZjEnrollKeyVO vo) {
        return AppResponse.successData(eduSyncZjEnrollIntegration.sync(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-删除信息同步", description = "省招生报名专库同步管理-删除信息同步")
    @PostMapping(value = "/eduSyncZj0025", produces = "application/json;charset=UTF-8")
    public AppResponse<RecruitStudentSyncRetVO> syncDelete(@RequestBody @Validated EduSyncZjDeleteKeyVO vo) {
        return AppResponse.successData(eduSyncZjDeleteIntegration.sync(vo));
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-报名信息生成", description = "省招生报名专库同步管理-报名信息生成")
    @PostMapping(value = "/eduSyncZj0026", produces = "application/json;charset=UTF-8")
    public AppResponse createBm(@RequestBody @Validated SyncStudentQueryVO vo) {
        eduSyncZjApplyIntegration.create(vo);
        return AppResponse.successMsg("生成成功！");
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库-报名信息批量同步", description = "省招生报名专库-报名信息批量同步")
    @PostMapping(value = "/eduSyncZj0027", produces = "application/json;charset=UTF-8")
    public AppResponse batchSyncBm(@RequestBody @Validated EduSyncZjApplyQueryVO vo) {
        eduSyncZjApplyIntegration.batchSync(vo);
        return AppResponse.successMsg("同步成功！");
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库-报名审核信息生成", description = "省招生报名专库-报名审核信息生成")
    @PostMapping(value = "/eduSyncZj0028", produces = "application/json;charset=UTF-8")
    public AppResponse createsh(@RequestBody @Validated SyncStudentQueryVO vo) {
        eduSyncZjApproveIntegration.create(vo);
        return AppResponse.successMsg("生成成功！");
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同-报名审核信息批量同步", description = "省招生报名专库-报名审核信息批量同步")
    @PostMapping(value = "/eduSyncZj0029", produces = "application/json;charset=UTF-8")
    public AppResponse batchSyncSh(@RequestBody @Validated EduSyncZjApproveQueryVO vo) {
        eduSyncZjApproveIntegration.batchSync(vo);
        return AppResponse.successMsg("同步成功！");
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库-报名录取信息生成", description = "省招生报名专库-报名录取信息生成")
    @PostMapping(value = "/eduSyncZj0030", produces = "application/json;charset=UTF-8")
    public AppResponse createLq(@RequestBody @Validated SyncStudentQueryVO vo) {
        eduSyncZjEnrollIntegration.create(vo);
        return AppResponse.successMsg("生成成功！");
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同-报名录取信息批量同步", description = "省招生报名专库-报名录取信息批量同步")
    @PostMapping(value = "/eduSyncZj0031", produces = "application/json;charset=UTF-8")
    public AppResponse batchSyncLq(@RequestBody @Validated EduSyncZjEnrollQueryVO vo) {
        eduSyncZjEnrollIntegration.batchSync(vo);
        return AppResponse.successMsg("同步成功！");
    }

    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同-删除信息批量同步", description = "省招生报名专库-删除信息批量同步")
    @PostMapping(value = "/eduSyncZj0032", produces = "application/json;charset=UTF-8")
    public AppResponse batchSyncDelete(@RequestBody @Validated EduSyncZjDeleteQueryVO vo) {
        eduSyncZjDeleteIntegration.batchSync(vo);
        return AppResponse.successMsg("同步成功！");
    }
    @Idempotent(expire = "PT2S") //2秒内防重复提交
    @Operation(summary = "省招生报名专库同步管理-清除处理缓存", description = "省招生报名专库同步管理-清除处理缓存")
    @PostMapping(value = "/eduSyncZj0033", produces = "application/json;charset=UTF-8")
    public AppResponse batchSyncDelete(@RequestBody @Validated BaseVO vo) {
        eduSyncZjApplyIntegration.clearCache(vo);
        return AppResponse.successMsg("清除成功！");
    }

    @Operation(summary = "省招生报名专库同步管理-批量生成报名数据", description = "省招生报名专库同步管理-批量生成报名数据")
    @PostMapping(value = "/eduSyncZj0034", produces = "application/json;charset=UTF-8")
    public AppResponse batchCreateApply(@RequestBody @Validated EduSyncZjApplyQueryVO vo) {
        eduSyncZjApplyIntegration.batchCreateApply(vo);
        return AppResponse.successMsg("操作成功！");
    }

    @Operation(summary = "省招生审核专库同步管理-批量生成审核数据", description = "省招生审核专库同步管理-批量生成审核数据")
    @PostMapping(value = "/eduSyncZj0035", produces = "application/json;charset=UTF-8")
    public AppResponse batchCreateApprove(@RequestBody @Validated EduSyncZjApproveQueryVO vo) {
        eduSyncZjApplyIntegration.batchCreateApprove(vo);
        return AppResponse.successMsg("操作成功！");
    }

    @Operation(summary = "省招生录取专库同步管理-批量生成录取数据", description = "省招生录取专库同步管理-批量生成录取数据")
    @PostMapping(value = "/eduSyncZj0036", produces = "application/json;charset=UTF-8")
    public AppResponse batchCreateEnroll(@RequestBody @Validated EduSyncZjEnrollQueryVO vo) {
        eduSyncZjApplyIntegration.batchCreateEnroll(vo);
        return AppResponse.successMsg("操作成功！");
    }

    @Operation(summary = "省招生专库同步管理-批量同步删除数据", description = "省招生专库同步管理-批量同步删除数据")
    @PostMapping(value = "/eduSyncZj0037", produces = "application/json;charset=UTF-8")
    public AppResponse batchCreateDelete(@RequestBody @Validated EduSyncZjDeleteQueryVO vo) {
        eduSyncZjApplyIntegration.batchCreateDelete(vo);
        return AppResponse.successMsg("操作成功！");
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "省招生专库同步管理-报名excel导出",description = "省招生专库同步管理-报名excel导出")
    @PostMapping(value = "/eduSyncZj0038", produces = "application/json;charset=UTF-8")
    @NoSignCrypto
    public void exportZJApplyInfo(@RequestBody @Validated EduSyncZjApplyQueryVO vo, HttpServletResponse response) {
        eduSyncZjApplyIntegration.exportZJApplyInfo(vo,response);
    }

    @Idempotent(expire="PT2S") //2秒内防重复提交
    @Operation(summary = "省招生专库同步管理-模板下载",description = "省招生专库同步管理-模板下载")
    @PostMapping(value = "/eduSyncZj0039", produces = "application/json;charset=UTF-8")
    @NoSignCrypto
    public void downloadZJApplyInfo(
            HttpServletRequest request,
            @RequestParam Map<String, Object> paramMap,
            @RequestBody(required = false) String body,
            HttpServletResponse response) {
        ExcelVO vo = null;
        if (StringUtils.isNotBlank(body)) {
            vo = JSON.parseObject(body, ExcelVO.class);
        } else {
            vo = new ExcelVO();
            if (paramMap.get("modelCode") != null) {
                vo.setModelCode(paramMap.get("modelCode").toString());
            }
            if (paramMap.get("excelVersion") != null) {
                vo.setExcelVersion(paramMap.get("excelVersion").toString());
            }
            if (paramMap.get("rows") != null) {
                vo.setRows(Integer.parseInt(paramMap.get("rows").toString()));
            }
            if (paramMap.get("dictMap") != null) {
                vo.setDictMap(
                        (Map<String, List<SelectVO>>)
                                JSON.parse(JSON.toJSONString(paramMap.get("dictMap"))));
            }
        }
        vo.setAccessToken(ServiceRequestUtil.getAccessToken(request, response));
        if (StringUtils.isBlank(vo.getModelCode())) {
            throw new AppException("excel模板编号不能为空");
        }
        eduSyncZjApplyIntegration.downloadModel(vo, response);
    }
}
